package com.lc202310;

import java.util.Stack;

/**
 * Description:
 *
 * @Create 2023/10/5 14:55
 * @Version 1.0
 */
public class BrowserHistory {
    private Stack<String> back;
    private Stack<String> forward;

    public BrowserHistory(String homepage) {
        this.back = new Stack<>();
        this.forward = new Stack<>();
        back.add(homepage);
    }

    public void visit(String url) {
        back.push(url);
        forward.clear();
    }

    public String back(int steps) {
        for (int i = 0; i < steps && back.size() > 1; i++) {
            forward.push(back.pop());
        }
        return back.peek();
    }

    public String forward(int steps) {
        for (int i = 0; i < steps && !forward.empty(); i++) {
            back.push(forward.pop());
        }
        return back.peek();
    }
}
